package se.webbzon.boltzmann.game.object.pickup;

import java.nio.ByteBuffer;

import se.webbzon.boltzmann.environment.AbstractEnvironment;
import se.webbzon.oschi01.friendly.Friendly;
import se.webbzon.oschi01.worldeditor.WorldStaticObjectDeflation;

public class PickupDeflation extends WorldStaticObjectDeflation {
	
	private long id;
	
	private PickupEnum type;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new empty pickup deflation. **/
	public PickupDeflation(int deflationProperties) {
		super(deflationProperties, null);
	}

	/** Creates a new pickup deflation of an existing pickup. **/
	public PickupDeflation(int deflationProperties, Pickup pickup) {
		super(deflationProperties, null, pickup);
		id = pickup.getId();
		type = pickup.getType();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void inflate(ByteBuffer buff) {
		super.inflate(buff);
		id = buff.getLong();
		type = PickupEnum.values()[buff.getInt()];
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff = super.deflate(allocate + 12);
		buff.putLong(id);
		buff.putInt(type.ordinal());
		return buff;
	}
	
	/*============================================================
	Friendly Methods
	============================================================*/
	
	/** Creates a new pickup from this pickup deflation. **/
	@Friendly Pickup makePickup(AbstractEnvironment env) {
		Pickup pickup = new Pickup(env,id,type);
		pickup.setPosition(getX(), getY(), getZ());
		pickup.setSize(getWidth(), getHeight(), getDepth());
		pickup.setRotation(getEX(), getEY(), getEZ(), getAngle());
		
		return pickup;
	}

}
